package org.kordakus.shoot;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.joda.time.DateTime;
import org.kordakus.shoot.model.ImageFile;

public class ShootContext
{

	public static final String				PROPERTY_IMAGE_LIST	= "images";

	private final PropertyChangeSupport		_support			= new PropertyChangeSupport(this);

	private final List<ImageFile>			_images				= new ArrayList<ImageFile>();

	private final Map<ImageFile, DateTime>	_session			= new HashMap<ImageFile, DateTime>();

	public ShootContext()
	{
	}

	public List<ImageFile> getImages()
	{
		return Collections.unmodifiableList(_images);
	}

	public void addImage(ImageFile image)
	{
		if (image != null && !_images.contains(image))
		{
			addImages(Collections.singletonList(image));
		}
	}

	public void addImages(Collection<ImageFile> images)
	{
		int current = images.size();
		if (images != null)
		{
			_images.addAll(images);
			_support.firePropertyChange(PROPERTY_IMAGE_LIST, current, _images.size());
		}
	}

	public void removeImage(ImageFile image)
	{
		_images.remove(image);
	}

	public int getImageCount()
	{
		return _images.size();
	}

	public DateTime getDateTime(ImageFile image)
	{
		return _session.get(image);
	}

	public void setDateTime(ImageFile image, DateTime taken)
	{
		_session.put(image, taken);
	}

	public void addPropertyListener(PropertyChangeListener listener)
	{
		_support.addPropertyChangeListener(listener);
	}

	public void removePropertyListener(PropertyChangeListener listener)
	{
		_support.removePropertyChangeListener(listener);
	}

	public void addPropertyListener(String name, PropertyChangeListener listener)
	{
		_support.addPropertyChangeListener(name, listener);
	}

}
